package ThreadDeath;

/**
 * @author 李泽伟
 */
public class Main {
    public static void main(String[] args) {
        StringBuffer sb1 = new StringBuffer();
        StringBuffer sb2 = new StringBuffer();

        new Thread(){
            @Override
            public void run() {
                synchronized (sb1){
                    sb1.append("a");
                    sb2.append("b");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (sb2){
                        sb1.append("1");
                        sb2.append("2");
                    }
                    System.out.println(sb1);
                    System.out.println(sb2);
                }
            }
        }.start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (sb2){
                    sb1.append("c");
                    sb2.append("d");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (sb1){
                        sb1.append("3");
                        sb2.append("4");
                    }
                    System.out.println(sb1);
                    System.out.println(sb2);
                }
            }
        }){}.start();
    }
}
